
% tai2brk_ctr
% Chris Whalen
% University of Illinois
% 05/20/04 - Date Created
% 07/28/05 - Last Modified

% tai2brk - this program takes the tai structure and converts to brik coords
% input  - tai structure in ALI
% output - tai structure in RAI 

function [tai] = tai2brk_ctr(tai,mri_dim)


i_Na = 9; i_LPA=10; i_RPA=11; 

% Placing Scaling Factor in RAI
temp(1)=tai.scale(2);
temp(2)=tai.scale(1);
temp(3)=tai.scale(3);
tai.scale=temp;

% Placing tai RAI Orientation 
for i_tai=1:size(tai.xyz,1)
 temp(1)=mri_dim.x - tai.xyz(i_tai,2);  
 temp(2)=tai.xyz(i_tai,1);  % 1
 temp(3)=tai.xyz(i_tai,3);  % 3
 tai.xyz(i_tai,:)=temp;
end

tai.origin= (tai.xyz(i_LPA,:)+tai.xyz(i_RPA,:))/2; % (LPA+RPA)/2

for i=i_Na:i_RPA
    tai.fid(i + 1 - i_Na,:) = tai.xyz(i,:);
end

% Place fiducials (tai.fid) in RAI origin (LPA+RPA)/2
for i=1:3
    tai.fid(i,:) = tai.fid(i,:) - tai.origin(1,:);  
end







